package com.zzyl.serve.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zzyl.serve.domain.*;
import com.zzyl.serve.vo.AllFamilyVo;
import com.zzyl.serve.vo.FamilyVo;
import org.apache.ibatis.annotations.Insert;
import com.zzyl.serve.domain.*;
import com.zzyl.serve.dto.DeviceDataDayDto;
import com.zzyl.serve.vo.AllFamilyVo;
import com.zzyl.serve.vo.DeviceDataDayVo;
import com.zzyl.serve.vo.DeviceDataWeekVo;
import com.zzyl.serve.vo.FamilyVo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;


import java.time.LocalDateTime;
import java.util.List;
import com.zzyl.serve.domain.FamilyMember;

/**
 * 老人家属Mapper接口
 * 
 * @author itheima
 * @date 2025-03-12
 */
@Mapper
public interface FamilyMemberMapper extends BaseMapper<FamilyMember>
{
    /**
     * 查询老人家属
     * 
     * @param id 老人家属主键
     * @return 老人家属
     */
    public FamilyMember selectFamilyMemberById(Long id);

    /**
     * 查询老人家属列表
     * 
     * @param familyMember 老人家属
     * @return 老人家属集合
     */
    public List<FamilyMember> selectFamilyMemberList(FamilyMember familyMember);

    /**
     * 新增老人家属
     * 
     * @param familyMember 老人家属
     * @return 结果
     */
    public int insertFamilyMember(FamilyMember familyMember);

    /**
     * 修改老人家属
     * 
     * @param familyMember 老人家属
     * @return 结果
     */
    public int updateFamilyMember(FamilyMember familyMember);

    /**
     * 删除老人家属
     * 
     * @param id 老人家属主键
     * @return 结果
     */
    public int deleteFamilyMemberById(Long id);

    /**
     * 批量删除老人家属
     * 
     * @param ids 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteFamilyMemberByIds(Long[] ids);


    @Select("select * from elder where id_card_no = #{idCard}")
    Elder getElderByIdCard(String idCard);
    @Insert("insert into family_member_elder(family_member_id, elder_id,remark) values(#{familyMemberId}, #{id},#{remark})")
    void bindFamily(@Param("familyMemberId") Long userId, @Param("id") Long id,@Param("remark") String remark);
    @Select("select * from family_member_elder where elder_id = #{id}")
    FamilyMemberElder findFamilyMemberIfRepete(Long id);
//    @Select("select family_member_elder.family_member_id, family_member_elder.elder_id,family_member_elder.id, elder.name as elderName\n" +
//            "        from family_member_elder\n" +
//            "                 left join elder on family_member_elder.elder_id = elder.id")
    List<FamilyVo> findFamily();

    List<AllFamilyVo> findByPage();
    @Select("select * from device where product_key= #{productKey} and device_name=#{deviceName} ")
    Device getDeviceById(@Param("productKey") String productKey,@Param("deviceName") String deviceName);
    @Select("select * from device_data where product_key = #{productKey}")
    DeviceData findDeviceData(String productKey);

    String queryDeviceDataListByDay(@Param("dateTime") LocalDateTime dateTime,@Param("endTime") LocalDateTime endTime,@Param("iotId") String iotId,@Param("functionId") String functionId);

    List<Elder> queryFamilyMemberElder(@Param("familyMemberElder") Long userId);

    List<DeviceData> queryDeviceDataListByWeek(@Param("accessLocation") String elderName);
}
